package com.seu.nic.component.controller;

import com.seu.nic.component.service.AdcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 教职工基本信息 前端控制器
 * </p>
 *
 * @author wyd
 * @since 2024-04-22
 */
@Slf4j
@Controller
@RequestMapping("/adc-server")
public class HealthController {

    @Autowired
    private AdcService adcService;

    private int healthCheckCount = 0;

    @ResponseBody
    @RequestMapping(value = "/health", method = RequestMethod.GET)
    public String health(
            HttpServletRequest request, HttpSession httpSession,
            HttpServletResponse response
    ) {
        if(healthCheckCount < 5) {
            log.info("healthCheck id: " + httpSession.getId());
            healthCheckCount++;
        }
        return "success";
    }


    @ResponseBody
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String test(
            HttpServletRequest request, HttpSession httpSession,
            HttpServletResponse response) {
        adcService.broadcastMessage("send message to client");
        return "success";
    }


}


